class Key
  # Key components
  @@DES = 1
  # RSA
  @@MODULUS = 3
  @@EXPONENT = 4
  @@CRT_P = 5
  @@CRT_Q = 6
  @@CRT_DP1 = 7
  @@CRT_DQ1 = 8
  @@CRT_PQ = 9
  # key
  @@UNKNOWN = 0;
  @@SECRET  = 1;
  @@PRIVATE = 2;
  @@PUBLIC  = 3;
  
  #attr_accessor :ID
  
  def initialize
    @value_hash = Hash.new()
  end
  
  def self.PRIVATE
    return @@PRIVATE
  end
  
  def self.PUBLIC
    return @@PUBLIC
  end
  
  def self.SECRET
    return @@SECRET
  end
  
  def self.CRT_P
    return @@CRT_P
  end

  def self.CRT_Q
    return @@CRT_Q
  end

  def self.CRT_DP1
    return @@CRT_DP1
  end

  def self.CRT_DQ1
    return @@CRT_DQ1
  end

  def self.CRT_PQ
    return @@CRT_PQ
  end
          
  def self.DES
    return @@DES
  end
  
  def self.MODULUS
    return @@MODULUS
  end

  def self.EXPONENT
    return @@EXPONENT
  end
    
  def getComponent(key_type)
    return @value_hash[key_type]
  end
  
  def setComponent(key_type,bs_value)
    @value_hash[key_type] = bs_value
    if key_type == @@DES
        @value_hash["type"] = @@SECRET
        @value_hash["size"] = ( bs_value.getBytes().length << 3 )
    elsif key_type == @@CRT_P || key_type == @@CRT_Q || key_type == @@CRT_PQ || key_type == @@CRT_DP1 || key_type == @@CRT_DQ1
        @value_hash["size"] = ( bs_value.getBytes().length << 4 )
        @value_hash["type"] = @@PRIVATE
    elsif key_type == @@MODULUS
        @value_hash["size"] = ( bs_value.getBytes().length << 3 )
        @value_hash["type"] = @@PUBLIC
    end
  end
  
  def getSize
    return @value_hash["size"]
  end
  
  def setSize(size)
    @value_hash["size"] = size
  end
  
  def getType
    return @value_hash["type"]
  end

  def setWrapKey wrapkey
    @value_hash['wrap_key'] = wrapkey
  end
  
  def getWrapKey
    return @value_hash['wrap_key']
  end
  
  def setWrapMech wrap_mech
    @value_hash['wrap_mech'] = wrap_mech
  end
  
  def getWrapMech
    return @value_hash['wrap_mech']
  end
end